package com.ymk.cmd;

import com.ymk.base.cmd.ACmd;
import com.ymk.base.cmd.CmdSign;
import com.ymk.base.mybatis.Pagination;
import com.ymk.base.utlis.ParamsBuilder;
import com.ymk.bo.stat.StatMchDayBO;
import com.ymk.core.code.cmd.StatMchCmdCode;
import com.ymk.service.IStatMchDayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Service
public class StatMchDayListCmd extends ACmd {

    @Override
    public CmdSign executeMop(HttpServletRequest request, CmdSign sign) throws Exception {
        CmdSign respSign = new CmdSign(sign);
        StatMchDayBO reqData = super.getData(sign, StatMchDayBO.class);

        ParamsBuilder paramsBuilder = ParamsBuilder.newBuild()
            .setReturnStruct(sign.getReturnStruct());
        Pagination pagination = sign.buildPage();
        pagination.setParams(paramsBuilder.build());
        List<StatMchDayBO> respDataList = this.StatMchDayService.listForPage(pagination);
        respSign.setPageInfo(pagination);
        respSign.setSource(super.getSource(respDataList));

        return respSign;
    }

    @Override
    public CmdSign executeSop(HttpServletRequest request, CmdSign sign) throws Exception {
        CmdSign respSign = new CmdSign(sign);
        StatMchDayBO reqData = super.getData(sign, StatMchDayBO.class);

        ParamsBuilder paramsBuilder = ParamsBuilder.newBuild()
                .addParam("mchId",sign.getMchId())
                .addParam("statDate",reqData.getStatDate())
                .setReturnStruct(sign.getReturnStruct());

        Pagination pagination = sign.buildPage();
        pagination.setParams(paramsBuilder.build());
        List<StatMchDayBO> respDataList = this.StatMchDayService.listForPage(pagination);
        respSign.setPageInfo(pagination);
        respSign.setSource(super.getSource(respDataList));

        return respSign;
    }

    @Override
    public CmdSign executeServer(HttpServletRequest request, CmdSign sign) throws Exception {
        CmdSign respSign = new CmdSign(sign);
        Map map = this.getData(sign,Map.class);

        List<StatMchDayBO> respDataList = this.StatMchDayService.list(map);
        respSign.setSource(super.getSource(respDataList));

        return respSign;
    }

    @Override
    public String getCmdCode() {
        return StatMchCmdCode.STAT_MCH_DAY_LIST;
    }

    @Autowired
    private IStatMchDayService StatMchDayService;
}